package edu.neusoft.springhtmldemo.util;

import java.math.BigDecimal;

public class CameraPanCoordinate {
    private String socketLine;
    private double abscissa;
    private double ordinate;
    private String resultSend;

    public CameraPanCoordinate(String socketLine) {
        this.socketLine = socketLine;
        while(this.getCoordinateBySocket()==-1){
            this.getCoordinateBySocket();
        }
    }

    public double getAbscissa() {
        return abscissa;
    }

    public void setAbscissa(double abscissa) {
        this.abscissa = abscissa;
    }

    public double getOrdinate() {
        return ordinate;
    }

    public void setOrdinate(double ordinate) {
        this.ordinate = ordinate;
    }

    private int getCoordinateBySocket(){
        String[] arr=this.socketLine.split(",");
//        判断数组越界
        if (arr.length<29){
            return -1;
        }
        System.out.println("-------数组长度"+arr.length);
        this.abscissa=Double.parseDouble(arr[29]);
        this.ordinate=Double.parseDouble(arr[30]);
        System.out.println(this.abscissa+"===="+this.ordinate);
        return 0;
    }
    public String result(){
        int x= (int) (this.abscissa/320*128+64);
        System.out.println(this.abscissa/320.0);
        System.out.println(this.abscissa/320.0*128.0);
        if(x>127){
            x=127;
        }else if(x< 0){
            x= 0;
        }
        int y= (int) (this.ordinate/200*128+64);
        if(y>127){
            y=127;
        }else if(y< 0){
            y=0;
        }
        System.out.println(x+"---"+y);
        char res1=(char)x;
        char res2=(char)y;
        this.resultSend="#="+res1+res2+"*";
        return this.resultSend;
    }
}
